<?php
use yii\helpers\Url;
use app\models\Supplier;
use app\modules\Product\models\Product;
use yii\widgets\LinkPager;
use yii\helpers\ArrayHelper;
use app\components\JSSDK;

$supplier = Supplier::find()->where(['status'=>1])->asArray()->all();
$supplier = yii\helpers\ArrayHelper::map($supplier,'id','company');

$this->title = "航线列表";

$day_num = [1=>'1-5天',2=>'6-10天',3=>'11-15天',4=>'15天以上'];


//$pro_line = yii::$app->params['line'];

$from_all_city = (new \yii\db\Query())
    ->select(['COUNT(c.supplier_id) as f_city','p.id','c.supplier_id'])
    ->from('product as p')
    ->leftJoin('cruise as c','c.id = p.cruise_id')
    ->where(['p.status'=>1])
    ->andFilterWhere(['>=','p.go_time',$today])
    ->addGroupBy('c.supplier_id')
    ->orderBy('f_city desc')
    ->all();


$all_line = (new \yii\db\Query())
    ->select(['COUNT(line) as f_line','id','line'])
    ->from('product')
    ->where(['status'=>1])
    ->andFilterWhere(['>=','go_time',$today])
    ->addGroupBy('line')
    ->orderBy('f_line desc')
    ->all();

$pro_line = ArrayHelper::map($all_line,'line',function ($element) {
    return yii::$app->params['line'][$element['line']];
});


// $pro_city = ArrayHelper::map($from_all_city,'from_city',function ($element) {
//     return yii::$app->params['city'][$element['from_city']];
// });

$pro_city = ArrayHelper::map($from_all_city,'supplier_id',function($element) {
    return $element['supplier_id'];
});

foreach($pro_city as $key=>$val){
    $pro_city[$key] = $supplier[$val];
}


//邮轮公司logo
$logo_path = [
        3=>'/img/logo3/3.png',
        4=>'/img/logo3/4.png',
        5=>'/img/logo3/5.png',
        6=>'/img/logo3/6.png',
        7=>'/img/logo3/7.png',
        8=>'/img/logo3/8.png',
        9=>'/img/logo3/9.png',
        10=>'/img/logo3/10.jpg',
]; 

$jssdk = new JSSDK("wxdf104a667847eb11", "1e1b098e7c4f442d94fe3499463238f2");
$signPackage = $jssdk->GetSignPackage();

?>
<script type="text/javascript" src="/js/iconfont.js"></script>
<?= yii\web\View::registerCssFile("/css/front/index.css",['depends' => 'app\assets\MuiAsset']) ?>

<style type="text/css">
    .mui-bar-nav{background-color: #f7f7f8}
    .mui-tab-item{margin-top: 5px;}
    .city{background-color: #f7f7f7}
    .text-center{text-align: center;}
    .mui-popover {height: 300px;}
    .city{color: #0A95CC;margin-top: 0px;}
    .city p{color: #0A95CC;font-size: 16px;}
    .city .iconfont{color: #0A95CC;font-size: 18px;}
    .mui-card{margin: 0;}
    .mui-bar-tab{background-color:#FFF;}
    .mui-tab-item .tab-label {font-size: 0.7rem;}
    .mui-tab-item{margin-top: 5px;}
    .mui-tab-item .iconfont{margin-top: 8px;}
    .mui-bar-tab .mui-tab-item.mui-active{color: rgb(41, 167, 226);}
    .mui-bar-tab .mui-tab-item.nav-active{color: rgb(41, 167, 226);}
    .mui-checkbox input[type=checkbox]:checked:before, .mui-radio input[type=radio]:checked:before{color: rgb(41, 167, 226);}

    .pic-box{width: 100%;position: absolute;z-index: 2;left: 0;top: 50vw;background: url(/img/bg_opacity40.png);height: 10vw;}
    .pic-box-name{line-height: 10vw;font-size:1rem;color: #FFF;}
    .pic-top{position: absolute;left: 0;top:0;background:url(/img/bg_price.png);background-repeat:no-repeat;background-size: cover;/*padding: 4px;*/text-align: center;color: #FFFFFF;width:26vw;margin-left: 5%;height: 13vw;}

    .line-box{position:absolute;width:30%;height:60px;background:rgba(0,0,0,0.5);margin-left: 4%;margin-top: -20%;}
    .box-bl{border:1px solid; border-color:rgba(255,255,255,0.5);margin: 5px;height: 50px;}
    .box-bl p{color: #FFFFFF;font-size: 14px;text-align: center;height: 25px;line-height: 25px;margin: 0;font-weight: bold;}

    .icon {
       width: 1.4rem; height: 1.4rem;
       vertical-align: -0.3em;
       fill: currentColor;
       overflow: hidden;
    }
    .mui-card-new{background-color:transparent !important;box-shadow: none !important;}  
    .mui-card-new .mui-input-group{background-color:transparent}

    .mui-pagination>li>a, .mui-pagination>li>span{color: #a664a6;}
    .mui-pagination>li.mui-active>a, .mui-pagination>li.mui-active>a:active, .mui-pagination>li.mui-active>span, .mui-pagination>li.mui-active>span:active, .mui-pagination>li:active>a, .mui-pagination>li:active>a:active, .mui-pagination>li:active>span, .mui-pagination>li:active>span:active{border-color: #a664a6;background-color: #a664a6;}

    .line-list{padding:10px;margin:10px 0px;border-radius:0px;background-color: #FFFFFF;}

</style>

<nav class="mui-bar mui-bar-tab">
        <a class="mui-tab-item <?=(isset($params['lines']) && isset($pro_line[$params['lines']]))?'nav-active':'';?>"  href="#Pop_lines"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-youlungongsi1"></use></svg><br><span class="tab-label">
        <?php if(isset($params['lines']) && isset($pro_line[$params['lines']])){?>
              <?=$pro_line[$params['lines']];?>
        <?php }else{?>
              邮轮航线
        <?php }?>
        </span></a>
         <a class="mui-tab-item <?=(isset($params['from_city']) && isset($pro_city[$params['from_city']]))?'nav-active':'';?>"  href="#Pop_city"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-chengshishaixuan"></use></svg><br><span class="tab-label">
        <?php if(isset($params['from_city']) && isset($pro_city[$params['from_city']])){?>
        <?=$pro_city[$params['from_city']];?>
          <?php }else{?>
              邮轮公司
          <?php }?>
        </span></a>
        <a class="mui-tab-item <?=(isset($params['price']) && isset($price[$params['price']]))?'nav-active':'';?>"  href="#Pop_price"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-shijianshaixuan"></use></svg><br><span class="tab-label">
           <?php if(isset($params['price']) && isset($price[$params['price']])){?>
              <?=$price[$params['price']];?>
          <?php }else{?>
              时间
          <?php }?>
        </span></a>
        <a class="mui-tab-item  <?=(isset($params['day']) && isset($day_num[$params['day']]))?'nav-active':'';?>"  href="#Pop_day"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-rilishaixuan1"></use></svg><br><span class="tab-label">
          <?php if(isset($params['day']) && isset($day_num[$params['day']])){?>
              <?=$day_num[$params['day']];?>
          <?php }else{?>
              天数
          <?php }?>
        </span></a>
</nav>

<div class="mui-content">

   <div class="cruise-lines">
        
            <?php foreach($lines as $v){?>
            <div class="line-list" data-href="<?=Url::toRoute(['lines','id'=>$v->id])?>">
                     
                      <img  src="<?=\Yii::$app->params['qiniu_path'].$v->image->path.'?imageView2/1/w/360/h/220'?>" width="40%"  >
                      <div class="line-box">
                        <div class="box-bl">
                          <p><?=$v->go_time?></p>
                          <p><?=yii::$app->params['city'][$v->from_city]?>上船</p>
                        </div>  
                      </div>
                     
                      <div style="width:55%;float: right;">
                          <div class="mui-row">
                            <div class="mui-col-xs-12" style="font-size:0.8rem;color: #333;">
                            <?=$v->name?>
                            </div>
                          </div>  
                            <p style="font-size: 0.6em;margin: 5px 0;color: #666">
                                 <img src="<?=isset($logo_path[$v->cruise->supplier_id])?$logo_path[$v->cruise->supplier_id]:'/img/logo/400.png'?>" style="height:0.8rem;vertical-align: middle;line-height: 0.8rem" >
                                 <span style="font-size:0.8rem;height:0.8rem;vertical-align: middle;line-height: 0.8rem"><?=$supplier[$v->cruise->supplier_id]?></span>
                            </p>
                            <p class="color-b" style="margin:5px 0;">
                                <span style="font-size:1rem;color: #FA6114">
                                      ¥<?=floor($v->minPrice)?>
                                </span>
                                <span style="font-size: 0.6rem;color: #FA6114;">
                                       起/人
                                </span>
                            </p>
             
                      </div>
                   
              </div>
              <?php }?>
       
              <div class="mui-content-padded text-center">
                  
             <?= yii\widgets\LinkPager::widget(['pagination' => $provider->pagination,'lastPageLabel'=>false, 'firstPageLabel'=>false,'maxButtonCount'=>5,'activePageCssClass'=>'mui-active','disabledPageCssClass'=>'mui-disabled','nextPageLabel' => false,
'prevPageLabel' => false,'options'=>['class'=>'mui-pagination']]); ?>
              </div>
   </div>

    
</div>



<div id="Pop_day" class="mui-popover" style="height: 220px;">
            <div class="mui-popover-arrow"></div>
          
            <div class="mui-scroll-wrapper">
                
                <div class="mui-scroll">
                    <div class="mui-card mui-card-new">
                        <div class="mui-input-group" id="day">
                          <div class="mui-input-row mui-radio">                                
                                <label class="lines_label">不限天数</label>
                                <input class="day" name="day" type="radio" value="0" <?= (isset($params['day']) && $params['day'] == 0) ? 'checked' : ''?> >
                            </div>   
                          <?php foreach($day_num as $k=>$v){?>
                            <div class="mui-input-row mui-radio">
                                <label class="city_label"><?=$v?></label>
                                <input class="day" name="day" type="radio" value="<?=$k?>" <?= (isset($params['day']) && $params['day'] == $k) ? 'checked' : ''?> >
                            </div>
                          <?php };?> 
                            
                            
                        </div>
                    </div>
                </div>
            </div>
</div>

<div id="Pop_price" class="mui-popover" style="height: 300px;">
            <div class="mui-popover-arrow"></div>
           
            <div class="mui-scroll-wrapper">
               
                <div class="mui-scroll">
                    <div class="mui-card mui-card-new">
                        <div class="mui-input-group" id="price">
                       
                             <div class="mui-input-row mui-radio">                                
                                <label class="lines_label">不限时间</label>
                                <input class="price" name="price" type="radio" value="0" <?= (isset($params['price']) && $params['price'] == 0) ? 'checked' : ''?> >
                            </div>   
                          <?php foreach($price as $k=>$v){?>
                            <div class="mui-input-row mui-radio">
                                <label class="city_label"><?=$v?></label>
                                <input class="price" name="price" type="radio" value="<?=$k?>" <?= (isset($params['price']) && $params['price'] == $k) ? 'checked' : ''?> >
                            </div>
                          <?php };?> 
                       
                            
                            
                        </div>
                    </div>
                </div>
            </div>
</div>

<div id="Pop_city" class="mui-popover" style="height: 220px;">
            <div class="mui-popover-arrow"></div>
           
            <div class="mui-scroll-wrapper">         
                <div class="mui-scroll">
                    <div class="mui-card mui-card-new">
                        <div class="mui-input-group" id="city">
                            <div class="mui-input-row mui-radio">                                
                                <label class="lines_label">不限</label>
                                <input class="city" name="city" type="radio" value="0" <?= (isset($params['from_city']) && $params['from_city'] == 0) ? 'checked' : ''?> >
                            </div>   
                          <?php foreach($pro_city as $k=>$v){?>
                            <div class="mui-input-row mui-radio">
                                <label class="city_label"><?=$v?></label>
                                <input class="city" name="city" type="radio" value="<?=$k?>" <?= (isset($params['from_city']) && $params['from_city'] == $k) ? 'checked' : ''?> >
                            </div>
                          <?php };?> 
                            
                        </div>
                    </div>
                </div>
            </div>
</div>

<div id="Pop_lines" class="mui-popover" style="height: 220px;">
            <div class="mui-popover-arrow"></div>
         
            <div class="mui-scroll-wrapper"> 
                <div class="mui-scroll">
                    <div class="mui-card mui-card-new">
                        <div class="mui-input-group" id="lines">
                           <div class="mui-input-row mui-radio">                                
                                <label class="lines_label">全部航线</label>
                                <input class="lines" name="lines" type="radio" value="0" <?= (isset($params['lines']) && $params['lines'] == 0) ? 'checked' : ''?> >
                            </div>   
                          <?php foreach($pro_line as $k=>$v){?>
                            <div class="mui-input-row mui-radio">                                
                                <label class="lines_label"><?=$v?></label>
                                <input class="lines" name="lines" type="radio" value="<?=$k?>" <?= (isset($params['lines']) && $params['lines'] == $k) ? 'checked' : ''?>>
                            </div>
                          <?php };?>     

                            
                        </div>
                    </div>
                </div>
            </div>
</div>

<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">

mui('body').on('tap',".img",function(){
    href = $(this).attr("data-href");
    document.location.href=href;
});
mui('body').on('tap',".pic-box",function(){
    href = $(this).attr("data-href");
    document.location.href=href;
});

mui('body').on('tap',".line-list",function(){
    href = $(this).attr("data-href");
    document.location.href=href;
});

var url = "<?= yii::$app->request->getUrl() ?>";    
var sign = (url.indexOf('?') == -1) ?  "?" : "&";


$(".day").change(function(){
      var day_val = 0;       
      day_val = $('input[name="day"]:checked').val();
      location.href = url + sign + "day=" + day_val+"&page=1";
});

$(".price").change(function(){
      var price_val = 0;       
      price_val = $('input[name="price"]:checked').val();
      location.href = url + sign + "price=" + price_val+"&page=1";
});


$(".city").change(function(){
      var city_val = 0;       
      city_val = $('input[name="city"]:checked').val();
      location.href = url + sign + "from_city=" + city_val+"&page=1";
});

$(".lines").change(function(){
     var lines_val = 0;
     var lines_val = $('input[name="lines"]:checked').val();
     location.href = url + sign + "lines=" + lines_val+"&page=1";
});

mui.init();
mui('body').on('shown', '.mui-popover', function(e) {});
mui('body').on('hidden', '.mui-popover', function(e) {});   

mui('.mui-scroll-wrapper').scroll({
    deceleration : 0.0005
});

mui('body').on('tap','a',function(){document.location.href=this.href;});



wx.config({
    debug: false,
    appId: '<?php echo $signPackage["appId"];?>',
    timestamp: '<?php echo $signPackage["timestamp"];?>',
    nonceStr: '<?php echo $signPackage["nonceStr"];?>',
    signature: '<?php echo $signPackage["signature"];?>',
    jsApiList: [
      // 所有要调用的 API 都要加到这个列表中
      'checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'onMenuShareQZone',
        'hideMenuItems',
        'showMenuItems',
        'hideAllNonBaseMenuItem',
        'showAllNonBaseMenuItem',

    ]
});


wx.ready(function(){
  var title = '邮轮旅游平台-航线列表';
  var desc = '邮轮旅游平台-航线列表';
  var link = '<?=sprintf("%s/front/default/index",yii::$app->request->getHostInfo())?>';
  var imgUrl = '<?=\Yii::$app->params['qiniu_path'].'/uploads/201706/1594cb321be769.jpg?imageView2/1/w/640/h/420';?>';
  
  wx.onMenuShareTimeline({
    title:desc,
    desc:desc,
    link:link,
    imgUrl:imgUrl,
    
  });
  wx.onMenuShareQQ({
    title:title,
    desc:desc,
    link:link,
    imgUrl:imgUrl,
    
  });
  wx.onMenuShareWeibo({
    title:title,
    desc:desc,
    link:link,
    imgUrl:imgUrl, 
  });
  wx.onMenuShareAppMessage({
    title:title,
    desc:desc,
    link:link,
    imgUrl:imgUrl,
  });
  wx.onMenuShareQZone({
    title:title,
    desc:desc,
    link:link,
    imgUrl:imgUrl,
    
  });
      
  
});


</script>
<?php app\components\JsBlock::end() ?>
